package com.smartwebee.android.blespp.hospital.fragment;


import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.smartwebee.android.blespp.R;
import com.smartwebee.android.blespp.databinding.FragmentSurveyBinding;
import com.smartwebee.android.blespp.eventbusclass.GoToViewPagerItem;
import com.smartwebee.android.blespp.hospital.HospitalScanActivity;
import com.smartwebee.android.blespp.utils.UIUtils;
import com.smartwebee.android.blespp.utils.Utils;

import org.greenrobot.eventbus.EventBus;

import static com.smartwebee.android.blespp.utils.Utils.MODE_TYPE;

/**
 * A simple {@link Fragment} subclass.
 */
public class SurveyFragment extends BaseFragment implements View.OnClickListener {
    private FragmentSurveyBinding binding;

    public SurveyFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_survey, container, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    private void initView() {
        binding.btnPlan1.setOnClickListener(this);
        binding.btnPlan2.setOnClickListener(this);
        binding.btnPlan3.setOnClickListener(this);
        binding.btnSet.setOnClickListener(this);
        binding.btnItem1.setOnClickListener(this);
        binding.btnItem2.setOnClickListener(this);
        binding.btnItem3.setOnClickListener(this);
        binding.btnItem4.setOnClickListener(this);
        binding.btnItem5.setOnClickListener(this);
        binding.btnItem6.setOnClickListener(this);
        binding.btnItem7.setOnClickListener(this);
        binding.btnItem8.setOnClickListener(this);
        binding.btnItem9.setOnClickListener(this);
        binding.btnItem10.setOnClickListener(this);
        binding.btnItem11.setOnClickListener(this);
        binding.btnItem12.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getActivity(), HospitalScanActivity.class);
        switch (v.getId()) {
            case R.id.btn_set:
                EventBus.getDefault().post(new GoToViewPagerItem(0));
                break;
            case R.id.btn_plan1:
                if (Utils.childItem.get(0).size() > 0) {
                    intent.putExtra(Utils.PLAN_TYPE, Utils.PLAN_TYPE_1);
                    startActivity(intent);
                } else {
                    UIUtils.showToast(getActivity(), "请添加一个项目");
                    EventBus.getDefault().post(new GoToViewPagerItem(0));
                }
                break;
            case R.id.btn_plan2:
                if (Utils.childItem.get(1).size() > 0) {
                    intent.putExtra(Utils.PLAN_TYPE, Utils.PLAN_TYPE_2);
                    startActivity(intent);
                } else {
                    UIUtils.showToast(getActivity(), "请添加一个项目");
                    EventBus.getDefault().post(new GoToViewPagerItem(0));
                }
                break;
            case R.id.btn_plan3:
                if (Utils.childItem.get(2).size() > 0) {
                    intent.putExtra(Utils.PLAN_TYPE, Utils.PLAN_TYPE_3);
                    startActivity(intent);
                } else {
                    UIUtils.showToast(getActivity(), "请添加一个项目");
                    EventBus.getDefault().post(new GoToViewPagerItem(0));
                }
                break;
            case R.id.btn_item1:
                intent.putExtra(MODE_TYPE, Utils.MODE_1);
                startActivity(intent);
                break;
            case R.id.btn_item2:
                intent.putExtra(MODE_TYPE, Utils.MODE_2);
                startActivity(intent);
                break;
            case R.id.btn_item3:
                intent.putExtra(MODE_TYPE, Utils.MODE_3);
                startActivity(intent);
                break;
            case R.id.btn_item4:
                intent.putExtra(MODE_TYPE, Utils.MODE_4);
                startActivity(intent);
                break;
            case R.id.btn_item5:
                intent.putExtra(MODE_TYPE, Utils.MODE_5);
                startActivity(intent);
                break;
            case R.id.btn_item6:
                intent.putExtra(MODE_TYPE, Utils.MODE_6);
                startActivity(intent);
                break;
            case R.id.btn_item7:
                intent.putExtra(MODE_TYPE, Utils.MODE_7);
                startActivity(intent);
                break;
            case R.id.btn_item8:
                intent.putExtra(MODE_TYPE, Utils.MODE_8);
                startActivity(intent);
                break;
            case R.id.btn_item9:
                intent.putExtra(MODE_TYPE, Utils.MODE_9);
                startActivity(intent);
                break;
            case R.id.btn_item10:
                intent.putExtra(MODE_TYPE, Utils.MODE_10);
                startActivity(intent);
                break;
            case R.id.btn_item11:
                intent.putExtra(MODE_TYPE, Utils.MODE_11);
                startActivity(intent);
                break;
            case R.id.btn_item12:
                intent.putExtra(MODE_TYPE, Utils.MODE_12);
                startActivity(intent);
                break;
        }
    }
}
